<?php

namespace app\admin\controller;


use think\Controller;
use think\Db;
use think\facade\Request;

class Banner extends  Controller
{
    protected $middleware = [
        'app\http\middleware\checkAdminToken::class'
    ];

    //返回指定字段的设置
    public function index()
    {
        $data=Db::table('banner')->order('index','desc')->all();
        $this->result($data,200,'');
    }

    //添加banner
    public function create()
    {
        $index=Request::param('index');
        $img=Request::param('img');

        $res=Db::table('banner')->insert([
            'index'=>$index,
            'img'=>$img,
            'add_time'=>time(),
        ]);
        $this->result($res,200,'');
    }

    //删除指定banner
    public function delete()
    {
        $banner_id=Request::param('banner_id');

        $res=Db::table('banner')->where([
            'id'=>$banner_id
        ])->delete();

        $this->result($res,200,'');
    }

}
